﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace MutiMenu
{
    /// <summary>
    /// Interaction logic for SettingDiag.xaml
    /// </summary>
    public partial class SettingDiag : Window
    {
         private MainWindow _mainWin = null;
        public MainWindow MainWin
        {
            get
            {
                return _mainWin;
            }
            set
            {
                _mainWin = value;
            }
        }
        
        public SettingDiag()
        {
            InitializeComponent();
        }
        public SettingDiag(MainWindow mainWin)
        {
            InitializeComponent();
            _mainWin = mainWin;
            SetAllImage();
        }
        private void SetAllImage()
        {
            _mainWin.SetButtonIcon(_mainWin.pathList[0], Image1);
            _mainWin.SetButtonIcon(_mainWin.pathList[1], Image2);
            _mainWin.SetButtonIcon(_mainWin.pathList[2], Image3);
            _mainWin.SetButtonIcon(_mainWin.pathList[3], Image4);
            _mainWin.SetButtonIcon(_mainWin.pathList[4], Image5);
            _mainWin.SetButtonIcon(_mainWin.pathList[5], Image6);
            _mainWin.SetButtonIcon(_mainWin.pathList[6], Image7);
            _mainWin.SetButtonIcon(_mainWin.pathList[7], Image8);

        }

        private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Microsoft.Win32.OpenFileDialog openDlg = new Microsoft.Win32.OpenFileDialog();
                if (openDlg.ShowDialog() == true)
                {
                    string str = openDlg.FileName;
                    System.Windows.Controls.Image image = (System.Windows.Controls.Image)sender;
                    string strIndex = image.Name.Substring(image.Name.Length - 1);
                    int imageIndex = int.Parse(strIndex) - 1;
                    _mainWin.pathList.RemoveAt(imageIndex);
                    _mainWin.pathList.Insert(imageIndex, str);
                    SetAllImage();
                    _mainWin.SetAllImage();
                    _mainWin.SetEnvironmentVariables();
                }
            }
            catch
            {
            }

        }
    }
}
